package com.atmaowei.controller;

import com.atmaowei.common.Result;
import com.atmaowei.controller.request.BaseRequest;
import com.atmaowei.controller.request.CoursePageRequest;
import com.atmaowei.controller.request.CourseRecordPageRequest;
import com.atmaowei.entity.CourseRecord;
import com.atmaowei.entity.Sct;
import com.atmaowei.service.SelectCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/selectCourse")
public class SelectCourseController {

    @Autowired
    private SelectCourseService selectCourseService;

    @GetMapping("/page")
    public Result page(BaseRequest baseRequest) {
        return Result.success(selectCourseService.page(baseRequest));
    }

    @GetMapping("/recordPage/{sno}")
    public Result recordPage(@PathVariable String sno, CourseRecordPageRequest courseRecordPageRequest) {
        return Result.success(selectCourseService.recordPage(courseRecordPageRequest));
    }

    @GetMapping("/addSct/{sno}/{cno}/{tno}")
    public Result addSct(@PathVariable String sno, @PathVariable String cno, @PathVariable String tno) {
        selectCourseService.addSct(sno, cno, tno);
        return Result.success();
    }

    @GetMapping("/querySct/{sno}/{cno}/{tno}")
    public Result querySct(@PathVariable String sno, @PathVariable String cno, @PathVariable String tno) {
        Sct sct = selectCourseService.querySct(sno, cno, tno);
        if (sct != null) {
            return Result.error();
        }
        return Result.success();
    }

    @GetMapping("/cancelSct/{sno}/{cno}/{tno}")
    public Result cancelSct(@PathVariable String sno, @PathVariable String cno, @PathVariable String tno) {
        selectCourseService.cancelSct(sno,cno,tno);
        return Result.success();
    }

    @PutMapping("/updatePassword/{sno}/{password}")
    public Result updatePassword(@PathVariable String sno, @PathVariable String password) {
        selectCourseService.updatePassword(sno, password);
        return Result.success();
    }

}
